package com.apimarket.entity;

import java.util.List;

/**
 * 为适配PageHelper插件响应格式做的适配
 *
 * @author yyc
 */
public class PageModel<T> {
    private Long total;

    private List<T> list;

    private int pageNum;

    private int pageSize;

    private int size;

    private long startRow;

    private Long endRow;

    private Long pages;

    private Long prePage;

    private Long nextPage;

    private boolean isFirstPage;

    private boolean isLastPage;

    private boolean hasPreviousPage;

    private boolean hasNextPage;

    private int navigatePages;

    private int[] navigatePageNums;

    private int navigateFirstPage;

    private int navigateLastPage;

    public PageModel(Long total, int pageNum, int pageSize, List<T> dataList) {
        this.total = total;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.list = dataList;

        /** 由以上四个值推理*/
        this.size = dataList.size();
        this.startRow = (pageNum - 1) * pageSize + 1;
        this.endRow = this.startRow + dataList.size() - 1;
        this.pages = (total % pageSize == 0 ? total / pageSize : (total / pageSize) + 1);
        this.prePage = (long) (pageNum == 1 ? 1 : pageNum - 1);
        this.nextPage = (pageNum == this.pages ? this.pages : pageNum + 1);
        this.isFirstPage = (pageNum == 1);
        this.isLastPage = (pageNum == this.pages);
        this.hasNextPage = !(pageNum == this.pages);
        this.hasPreviousPage = !(pageNum == 1);

        /** navigate前缀变量意义不明 先默认初始化*/
        this.navigateFirstPage = 0;
        this.navigatePageNums = null;
        this.navigateFirstPage = 0;
        this.navigateLastPage = 0;
    }
}
